from django.views import View

from Venue.models import Venue
from sportsground.utils import Req
from sportsground.utils.Res import Res
from sportsground.utils.views import LoginRequired


class InfoView(View):
    """ 馆场信息 """

    def get(self, request):
        """ 查询 """
        venue = Venue.objects.get(id=1)
        # todo
        return Res.Json(Res.OK, result=venue.Info())

    @LoginRequired.Venue
    @Req.getJson
    def put(self, request):
        """ 修改 """
        name = request.json_dict.get("name")
        notice = request.json_dict.get("notice")

        venue = request.user.venue

        if name:
            venue.name = name
        if notice:
            venue.notice = notice

        venue.save()
        return Res.Json(Res.OK, result=venue.Info())
